<template>
  <div>
    <div class="w">
      <div class="headers" v-if="commentLists">
        <div class="headers-son">
          <div class="fanhui" @click="signOut">
            <span class="iconfont icon-jiantouzuo"></span>
          </div>
          <div class="users">
            <div class="pic">
              <img :src="commentLists[0].touxiang" alt="" />
            </div>
            <div class="user-name">
              <p>{{ commentLists[0].userName }}</p>
            </div>
          </div>
          <div class="followbtn">
            <button>关注</button>
          </div>
          <div class="more">
            <span class="iconfont icon-qita"></span>
          </div>
        </div>
      </div>

      <div class="pictures" v-if="commentLists">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item
            v-for="(item, index) in commentLists[0].worksImg"
            :key="index"
          >
            <img :src="item" width="100%" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>

      <div class="describe" v-if="commentLists">
        <p>{{ commentLists[0].works }}</p>
        <div class="foodName">{{ commentLists[0].zhuti }}</div>
        <p class="timeorrenshu">
          <span>{{ commentLists[0].times }}</span
          >·
          <span>{{ commentLists[0].yulan }}次浏览</span>
        </p>
      </div>

      <div class="zanshang" v-if="commentLists">
        <div class="zanrenshu">{{ this.$route.query.fabulous }}人赞赏</div>
        <div class="pinglun">
          <div class="pinglun-son" v-for="(k, i) in plunList" :key="i">
            <div class="pinglun-user">
              <div class="usernames">
                <div class="img">
                  <img :src="k.articleImg" alt="" />
                </div>
                <div class="name-user">
                  {{ k.names }}
                </div>
              </div>
              <div class="zanNum">
                <span>{{ k.articlefabulous }}</span>
                <span class="iconfont icon-dianzan1"></span>
              </div>
            </div>
            <div class="pinglun-text">
              <p>{{ k.content }}</p>
            </div>
          </div>
        </div>
      </div>

      <div class="baikuai"></div>
      <div class="personal" v-if="commentLists">
        <div class="input">
          <input
            type="text"
            placeholder="写评论...."
            v-model="titles"
            @keyup.13="pinlun"
          />
        </div>
        <div class="personal-zan">
          <span
            class="iconfont icon-dianzan1"
            :style="{ color: zhuantai }"
          ></span>
          <span>{{ this.$route.query.fabulous }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { recommendData } from "../api/home.js";
export default {
  data() {
    return {
      commentId: null,
      commentLists: null,
      titles: "",
      plunList: [],
      zhuantai: "black",
    };
  },
  methods: {
    signOut() {
      this.$emit("signOut");
      this.$router.go(-1);
    },
    pinlun() {
      if (this.titles != "") {
        this.plunList.unshift({
          articleImg: "../assets/img/touxiang.jpg",
          names: "ysjx",
          content: this.titles,
          articlefabulous: 0,
        });

        console.log(this.plunList);
        window.localStorage.setItem(
          "comment" + this.commentId,
          JSON.stringify(this.plunList)
        );
        this.titles = "";
      }
    },
  },
  created() {
    this.commentId = this.$route.query.id;
    if (window.localStorage.getItem("comment" + this.commentId)) {
      this.plunList = JSON.parse(
        window.localStorage.getItem("comment" + this.commentId)
      );
    }
    this.zhuantai = this.$route.query.zhuantai;
    recommendData().then((data) => {
      this.commentLists = data.follow.filter(
        (item) => item.id == this.commentId
      );
    });
  },
};
</script>

<style lang="scss" scoped>
.headers {
  z-index: 10;
  position: sticky;
  top: 0;
  .headers-son {
    width: 100%;
    height: 60px;
    background-color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .users {
      display: flex;
      align-items: center;
      .pic {
        height: 36px;
        width: 36px;
        border-radius: 50%;
        overflow: hidden;
        margin-right: 5px;
        img {
          width: 36px;
        }
      }
    }
    .followbtn {
      width: 55px;
      height: 33px;
      button {
        width: 100%;
        height: 100%;
        background-color: #f8e9e7;
        color: #ecc2b9;
        border-radius: 16px;
        border: 0;
        outline: none;
      }
    }
  }
}

.pictures {
  .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    text-align: center;
  }
}

.describe {
  padding: 0 20px;
  border-bottom: 1px solid #ddd;
  p {
    line-height: 30px;
  }
  .foodName {
    display: inline-block;
    padding: 10px 15px;
    background-color: #f2f2f2;
    border-radius: 12px;
  }
  .timeorrenshu {
    font-size: 12px;
    color: #b0afaf;
    margin-top: 15px;
    margin-bottom: 12px;
  }
}
.zanshang {
  padding: 0 20px;
  .zanrenshu {
    height: 43px;
    line-height: 43px;
    font-weight: bold;
  }
  .pinglun {
    .pinglun-son {
      .pinglun-user {
        height: 42px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .usernames {
          display: flex;
          align-items: center;
          .img {
            height: 42px;
            width: 42px;
            border-radius: 50%;
            overflow: hidden;
            margin-right: 10px;
            img {
              width: 42px;
            }
          }
          .name-user {
            color: #cfcfcf;
          }
        }
      }
      .pinglun-text {
        padding-left: 52px;
        p {
          height: 30px;
        }
      }
    }
  }
}

.personal {
  position: sticky;
  bottom: 0;
  padding: 0 20px;
  height: 50px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: white;
  .input {
    width: 194px;
    background-color: #f6f6f6;
    height: 16px;
    padding: 8px 15px 12px 15px;
    border-radius: 16px;
    input {
      background-color: #f6f6f6;
      height: 12px;
      font-size: 12px;
      width: 100%;
      border: 0;
      outline: none;
    }
  }
  .personal-zan {
    .iconfont {
      font-size: 20px;
    }
  }
}
</style>